#include <bits/stdc++.h>
#include <string>
using namespace std;


int main()
{
	int k,n,price[100001],f[100001],l[100001];
	cin >> k;
	while(k--){
		cin >> n;
		int minn = 9999999,maxx = -9999999;
		f[0] = 0;
		l[n-1] = 0;
        for(int i=0;i<n;i++){
			cin >> price[i];
			minn = min(minn,price[i]);
            f[i] = max(price[i]-minn,f[i-1]);
		}
		for(int i=n-1;i>=0;i--){
			maxx = max(maxx,price[i]);
			l[i] = max(maxx-price[i],l[i+1]);
		}
		int r = -1;
		for(int i=0;i<n;i++){
			r = max(r,f[i]+l[i]);
		}
		cout << r << endl;
	}

	return 0;
}